from utils import pandigitals
from utils import xprimes
import sys

primes = [i for i in xprimes(10**6)]

for i in range(9, 0, -1):
    for x in map(int, pandigitals(range(1, i+1), i))[::-1]:
        is_prime = True
        for y in primes:
            if x % y == 0:
                is_prime = False
                break
        if is_prime:
            print x
            sys.exit(0)

